from robot.libraries.BuiltIn import BuiltIn
from comm_lib.util import Util


class ZhwAppVerify(object):
    @staticmethod
    def verify_status_code():
        code = BuiltIn().run_keyword('get status code')
        Util.str_assert(code, '200')

    def get_response_content(self):
        self.verify_status_code()
        response = BuiltIn().run_keyword('get resp json')
        state = response.get('status')
        msg = response.get('message')
        return state, msg

    def common_verify(self):
        response = BuiltIn().run_keyword('get resp json')
        status = response.get('status')
        Util.str_assert('1', status)
        self.verify_status_code()

    def verify_invalid_login(self):
        state, msg = self.get_response_content()
        Util.str_assert('-1', state)
        Util.str_assert('登录已失效', msg)

    def verify_act_rent_detail_new(self, status):
        state, msg = self.get_response_content()
        Util.str_assert(state, status)
        if status == '0':
            message = '请求账号非法'
        elif status == '-1100':
            message = '该账号暂时无法租用,去看看别的账号吧！'
        elif status == '2002':
            message = '帐号为买卖帐号，无法租赁'
        elif status == '-1':
            message = '登录已失效'
        Util.str_assert(msg, message)

    def verify_check_user_is_anti_indulge(self):
        state, msg = self.get_response_content()
        Util.str_assert(state, '0')
        Util.str_assert('您当前未受到防沉迷限制！', msg)

    def verify_check_user_prize(self, param=None):
        state, msg = self.get_response_content()
        Util.str_assert(state, '0')
        if not param:
            message = '活动未开启'
        else:
            if param == 'hid':
                message = '缺少参数'
            elif param == 'token':
                message = '检测失败'
        Util.str_assert(message, msg)

    def verify_get_collect_list(self):
        state, msg = self.get_response_content()
        Util.str_assert(state, 1)
        Util.str_assert(msg, '请求成功')

    def verify_dian_pu_index(self):
        state, msg = self.get_response_content()
        Util.str_assert(state, 1)
        Util.str_assert(msg, '查询成功')

    def verify_get_collect_list_without_token(self):
        state, msg = self.get_response_content()
        Util.str_assert(state, -1)
        Util.str_assert(msg, '登录已失效')

    def verify_check_user_money_new(self):
        state, msg = self.get_response_content()
        Util.str_assert(state, 1)
        Util.str_assert(msg, '余额验证成功，用户可以租号！')

    def verify_msg_list(self):
        state, msg = self.get_response_content()
        Util.str_assert(state, 1)
        Util.str_assert(msg, '读取消息列表成功')

    def verify_msg_list_without_token(self):
        state, msg = self.get_response_content()
        Util.str_assert(state, -1)
        Util.str_assert(msg, '请登录后查看详细信息')

    def verify_success_status(self):
        state, msg = self.get_response_content()
        Util.str_assert(state, 1)
        Util.str_assert(msg, 'success')

    def verify_dian_pu_detail(self, exist=False):
        state, msg = self.get_response_content()
        Util.str_assert(state, 0)
        self.verify_status_code()
        if exist:
            Util.str_assert(msg, '店铺已经删除或不存在！')
        else:
            Util.str_assert(msg, '非法操作！')

    def verify_set_collect(self, set_type, status):
        state, msg = self.get_response_content()
        if status == '0':
            if set_type == 'set':
                message = '您已收藏，请勿重复收藏'
            elif set_type == 'cancel':
                message = '您已取消收藏，请勿重复取消'
            else:
                message = '您收藏的账号不存在，请核对后重试！'
        elif status == '1':
            if set_type == 'set':
                message = '收藏成功'
            elif set_type == 'cancel':
                message = '取消收藏成功'
        Util.str_assert(message, msg)
        Util.str_assert(state, status)

    def verify_get_unread_msg_list(self):
        state, msg = self.get_response_content()
        Util.str_assert(msg, '读取消息列表成功')
        Util.str_assert(state, 1)

    def verify_get_appraise_list(self, status, empty=False):
        state, msg = self.get_response_content()
        if empty:
            message = '帐号不能为空'
        else:
            message = ''
        Util.str_assert(msg, message)
        Util.str_assert(state, status)

    def verify_pay_way(self):
        state, msg = self.get_response_content()
        Util.str_assert(msg, '允许支付')
        Util.str_assert(state, 1)

    def verify_info_list(self):
        self.verify_status_code()
        response = BuiltIn().run_keyword('get resp json')
        state = response.get('status')
        msg = response.get('message')
        page = response.get('page')
        page_size = response.get('pagesize')
        Util.str_assert(msg, '')
        Util.str_assert(state, 1)
        req = BuiltIn().run_keyword('get req body')
        Util.str_assert(page, req.get('page'))
        Util.str_assert(page_size, req.get('pageSize'))
